package Testes;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.rowset.JdbcRowSet;

import sun.jdbc.odbc.JdbcOdbc;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import com.sun.rowset.JdbcRowSetImpl;

public class ConexaoTest {
	static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
	static final String DATABASE_URL = "jdbc:mysql://localhost/simfi";
	static final String username = "simfi";
	static final String password = "simfi123";

	public void ConexaoTest() {
		//Connection connection = null;
		//Statement statement = null;
		
		try{			
			Class.forName( JDBC_DRIVER);
			JdbcRowSet rowSet = new JdbcRowSetImpl();
			rowSet.setUrl(DATABASE_URL);
			rowSet.setUsername(username);
			rowSet.setPassword(password);
			rowSet.setCommand("SELECT *, FROM DEPARTAMENTO");
			rowSet.execute();
			
			ResultSetMetaData metaData = (ResultSetMetaData) rowSet.getMetaData();
			int numColunas = metaData.getColumnCount();
			System.out.println("departamentos ");
			
			for (int i = 1; i <= numColunas; i++) {
				System.out.printf("%-8s\t", metaData.getColumnName(i));
				System.out.println();
			}
			
			while (rowSet.next() ) {
				for (int i = 1; i <= numColunas; i++) {
					System.out.printf("%-8s\t", rowSet.getObject(i));
					System.out.println();
				}				
			}
			
		}catch (SQLException e1) {
			e1.printStackTrace();
			System.exit(1);
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.exit(1);
		}
}
	public static void main(String[] args) {
		System.out.println("inicio");
		ConexaoTest window = new ConexaoTest();
	}
}
